<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <!-- v-model="activeName" -->
      <el-tabs v-model="activeName" class="tabs">
        <el-tab-pane label="销售额" name="first" />
        <el-tab-pane label="访问量" name="second" />
      </el-tabs>
      <div class="right">
        <span @click="setDay">今日</span>
        <span @click="setWeek">本周</span>
        <span @click="setMonth">本月</span>
        <span @click="setYear">本年</span>
        <!-- v-model="value1" -->
        <el-date-picker
          v-model="date"
          class="date"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="-"
          size="mini"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
      </div>

    </div>
    <div>
      <el-row :gutter="10">
        <el-col :span="17">
          <div ref="bar" class="bar" />
        </el-col>
        <el-col :span="7" class="md">
          <h3>门店{{ title }}排名</h3>
          <ul>
            <li>
              <span class="rnum">0</span>
              <span>肯德基</span>
              <span class="hh">12563887</span>
            </li>
            <li>
              <span class="rnum">1</span>
              <span>肯德基</span>
              <span class="hh">12563887</span>
            </li>
            <li>
              <span class="rnum">2</span>
              <span>肯德基</span>
              <span class="hh">12563887</span>
            </li>
            <li>
              <span>3</span>
              <span>肯德基</span>
              <span class="hh">12563887</span>
            </li>
            <li>
              <span>4</span>
              <span>肯德基</span>
              <span class="hh">12563887</span>
            </li>
            <li>
              <span>5</span>
              <span>肯德基</span>
              <span class="hh">12563887</span>
            </li>
            <li>
              <span>6</span>
              <span>肯德基</span>
              <span class="hh">12563887</span>
            </li>
            <li>
              <span>7</span>
              <span>肯德基</span>
              <span class="hh">12563887</span>
            </li>
          </ul>
        </el-col>
      </el-row>
    </div>

  </el-card>
</template>

<script>
import echarts from 'echarts'
import dayjs from 'dayjs'

export default {
  data() {
    return {
      date: [],
      activeName: 'first',
      myCharts: null
    }
  },
  computed: {
    title() {
      return this.activeName == 'first' ? '销售额' : '访问量'
    }
  },
  watch: {
    title() {
      this.myCharts.setOption({

        title: {
          text: this.title + '趋势'
        }

      })
    }
  },
  mounted() {
    this.myCharts = echarts.init(this.$refs.bar)
    this.myCharts.setOption({
      title: {
        text: '销售额趋势'
      },
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'shadow'
        }
      },
      grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },
      xAxis: [
        {
          type: 'category',
          data: [],
          axisTick: {
            alignWithLabel: true
          }
        }
      ],
      yAxis: [
        {
          type: 'value'
        }
      ],
      series: [
        {
          name: 'Direct',
          type: 'bar',
          barWidth: '60%',
          data: [10, 45, 16, 48, 78, 89],
          color: 'yellowgreen'
        }
      ]
    })
  },
  methods: {
    setDay() {
      const start = dayjs().format()
      const end = dayjs().format()
      this.date = [start, end]
    },
    setWeek() {
      const start = dayjs().day(1).format('YYYY-MM-DD')
      const end = dayjs().day(7).format('YYYY-MM-DD')
      this.date = [start, end]
    },
    setMonth() {
      const start = dayjs().startOf('month').format('YYYY-MM-DD')
      const end = dayjs().endOf('month').format('YYYY-MM-DD')
      this.date = [start, end]
    },
    setYear() {
      const start = dayjs().startOf('year').format('YYYY-MM-DD')
      const end = dayjs().endOf('year').format('YYYY-MM-DD')
      this.date = [start, end]
    }
  }
}
</script>

<style scoped>
.tabs{
    width: 100%;
}
.clearfix{
    display: flex;
     position: relative;
    justify-content: space-between;
}
.date{
    width: 250px;
}
.right span {
    margin: 0px 10px;
}
.right{
    position: absolute;
  right: 0px;
}

.bar{
    width: 100%;
    height: 300px;
}
ul {
  list-style: none;
  width: 100%;
  height: 300px;
  padding: 0px;
}
ul li {
  height: 8%;
  margin: 10px 0px;
}
li span{
    margin: 0 10px;
}
.rnum{
      float: left;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: black;
    color: white;
    text-align: center;
}
.hh{
    float: right;
}
</style>
